using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public class UIN_HeroInfoAttrDetail : UIBaseNode
    {

        #region Template Generate,don't modify
        protected partial class UIB_UIN_HeroInfoAttrDetail
        {
            #region ObjectBinding Generate 
            public IQIGame.Onigao.Framework.ExButton buttonClose { protected set; get; }
            public GameObject attMould { protected set; get; }
            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExButton>("buttonClose", out var __tbv0);
                this.buttonClose = __tbv0;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("attMould", out var __tbv1);
                this.attMould = __tbv1;
            }

            #endregion ObjectBinding Generate 
        }
        #endregion Template Generate,don't modify

        #region fields & properties
        ListScrollAdapter<UIN_CommonAttribute> attrs = null;

        HeroData _heroData = null;

        protected UIB_UIN_HeroInfoAttrDetail ui { get; set; }
        #endregion

        protected override void BeforeInit()
        {
            ui = new UIB_UIN_HeroInfoAttrDetail();
            ui.InitBinding(this.csObjBind);
        }

        protected override void OnInit()
        {
            this.attrs = this.InitListScroll<UIN_CommonAttribute>(this.ui.attMould, this.OnAttrChanged);
            this.ui.buttonClose.onClick.AddListener(this.OnClickHide);
        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }

        protected override void OnDispose()
        {
            this._heroData = null;
        }

        public void Show(HeroData heroData)
        {
            this._heroData = heroData;
            if (heroData == null)
                return;
            this.Show();
            var attrs = APIUIHeroInfo.DetailAttributeIds;
            this.attrs.RefillCells(attrs.Length);
        }

        void OnAttrChanged(UIN_CommonAttribute item, int index)
        {
            var attrCid = APIUIHeroInfo.DetailAttributeIds[index];
            var attrVal = this._heroData.GetAttr(attrCid);
            item.Show(attrCid, attrVal);
        }

        void OnClickHide()
        {
            this.Hide();
        }
    }
}
